import json
import tablib


def to_formatted_table(tab_data):
    ds = tablib.Dataset()
    return ds.load(str(tab_data))


class ModelExt(object):
    def __repr__(self):
        fields = self.__dict__
        if "_sa_instance_state" in fields:
            del fields["_sa_instance_state"]

        return json.dumps(fields)

# By inheriting this class, you can print the formatted table using statement as follows:
# print(to_formatted_table(tab_data))
